/**
 * @description get api Data
 *
 * @author Candy <candy.yan@motionglobal.com>
 * @date  Creation Date 10/05/2018
 */

import axios from 'axios';
import qs from 'qs';
axios.defaults.withCredentials = true;
axios.defaults.baseURL = 'http://mock-data-data-api';
// axios.defaults.baseURL = 'http://192.168.50.89';

/**
 * Get captcha
 */
export const getCaptcha = () => axios({
  method: 'get',
  url: 'http://192.168.50.89/portal-api/get-captcha',
  params: {}
});

/**
 * login
 */
export const login = (username, password, captcha, rememberMe) => axios({
  method: 'post',
  // url: 'http://192.168.50.89/portal-api/login',
  // data: qs.stringify({ username, password, captcha})
  url: '/api/user/login',
  data: { username, password}
});

/**
 * Logout
 */
export const logout = () => axios({
  method: 'post',
  url: '/api/user/logout',
  data: qs.stringify({ })
});

/**
 * Password Reset
 */
export const passwordReset = (newPassword, confirmNewPassword) => axios({
  method: 'post',
  url: '/api/user/password-reset',
  data: qs.stringify({ newPassword, confirmNewPassword })
});

/**
 * getUserInfo
 */
export const getUser = (user_id = 1) => axios({
  method: 'get',
  url: '/api/user',
  params: {user_id}
});

/**
 * supplier-PO wait-to-confirm
 * status: wait-to-confirm / confirmed / wait to ship / shipped
 */
export const getSupplierPO = (status) => axios({
  method: 'get',
  url: '/api/supplier-PO',
  params: {status}
});

/**
 * supplier-PO wait-to-confirm submit confirmed data
 */
export const submitWaitToConfirm = ( confirmedData ) => axios({
  method: 'post',
  url: '/api/supplier-PO/wait-to-confirm',
  data: qs.stringify({ confirmedData })
});

/**
 * supplier-PO wait-to-confirm export excel
 */
export const waitToConfirmExcelExport = ( exportData) => axios({
  method: 'post',
  url: '/api/supplier-PO/wait-to-confirm/excel-export',
  data: qs.stringify({exportData})
});

/**
 * supplier-PO confirmed search
 */
export const searchConfirmedItems = (UPC) => axios({
  method: 'get',
  url: '/api/supplier-PO/confirmed',
  params: {UPC}
});

/**
 * supplier-PO wait to ship search
 */
export const searchWaitToShipItems = (UPC) => axios({
  method: 'get',
  url: '/api/supplier-PO/wait-to-ship',
  params: {UPC}
});

/**
 * supplier-PO wait-to-ship submit confirmed data
 */
export const submitWaitToShip = ( confirmedData ) => axios({
  method: 'post',
  url: '/api/supplier-PO/wait-to-ship',
  data: qs.stringify({ confirmedData })
});

/**
 * supplier-PO wait-to-ship export excel
 */
export const waitToShipExcelExport = ( exportData) => axios({
  method: 'post',
  url: '/api/supplier-PO/wait-to-ship/excel-export',
  data: {exportData}
});

/**
 * supplier-PO create shipment
 */
export const createShipment = ( data ) => axios({
  method: 'post',
  url: '/api/supplier-PO/wait-to-ship/create-ship',
  data: qs.stringify({data})
});

/**
 * supplier-PO shipment detail
 */
export const shipmentDetail = ( shipment ) => axios({
  method: 'get',
  url: '/api/supplier-PO/shipped/shipment-detail',
  data: qs.stringify({shipment})
});

/**
 * supplier-PO shipped search
 */
export const searchShippedItems = (shipment) => axios({
  method: 'get',
  url: '/api/supplier-PO/shipped',
  params: {shipment}
});

